<!--
 * @description  : 市管-添加日志
 * @descriptionDetail: 市管-添加日志
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-07-09 18:43:02
-->
<template>
  <view>
    <theme-navbar
      :is-white="false"
      :title="dayLog.logDate + '日志'"
      :custom-back="handlerBack"
      style="z-index: 99999"
    >
      <view class="nav-right-icon" v-if="!isDisabled" @tap="handlerSure">
        确定
      </view>
    </theme-navbar>
    <!-- 人员日志 -->
    <view style="padding: 5px 15px;">
      <u-collapse>
        <u-collapse-item :title="item.personName" :accordion="false" style="border-bottom: 1px solid #eee;" v-for="(item, index) in personWorks" :key="index">
          <u-row gutter="16">
            <u-col span="6" v-for="(ck, cIdx) in checkboxList" :key="cIdx">
              <u-cell-item class="cell cell-sub" :title="ck.value" :arrow="false">
                <u-switch :disabled="isDisabled || ck.isDisabled" slot="right-icon" v-model="item[ck.key]"></u-switch>
              </u-cell-item>
            </u-col>
          </u-row>
        </u-collapse-item>
      </u-collapse>
    </view>
    <u-field
      type="textarea"
      placeholder="请输入备注"
      style="height: 120px;"
      label-width="0"
      :disabled="isDisabled"
      v-model="remark"
    >
    </u-field>
    <!-- 操作提示信息 -->
    <view style="padding: 5px 15px;color: #666;">
      <view>1、报表由所对长填写 ，仅允许添加修改当日报表</view>
      <view>2、市场检查栏系统自动获取、更新，无需填写</view>
      <view>3、若当日（工作日）未填报，次日自动生成一张仅含市场检查的日志表</view>
    </view>
  </view>
</template>
<script>
import checkService from "@/service/check/check.service"
import {dateUtils,} from "@/common/util"
const NOW_DATE = dateUtils.dateFormat("yyyy-MM-dd", new Date());
export default {
  name: "AddLogDay",
  props: {
    dayLog: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      user: this.$storage.get(this.$rp.common.USER),
      isDisabled: this.dayLog.logDate !== NOW_DATE,
      checkboxList: [
        {key: "pcMWt01", value: "市场检查", isChecked: false, isDisabled: true,},
        {key: "pcMWt02", value: "打假破网", isChecked: false, isDisabled: false,},
        {key: "pcMWt03", value: "无证户监管", isChecked: false, isDisabled: false,},
        {key: "pcMWt04", value: "物流寄递监管", isChecked: false, isDisabled: false,},
        {key: "pcMWt05", value: "无证运输监管", isChecked: false, isDisabled: false,},
        {key: "pcMWt06", value: "案件办理", isChecked: false, isDisabled: false,},
        {key: "pcMWt07", value: "举报投诉处理", isChecked: false, isDisabled: false,},
        {key: "pcMWt08", value: "净化率考核", isChecked: false, isDisabled: false,},
        {key: "pcMWt09", value: "许可证工作", isChecked: false, isDisabled: false,},
        {key: "pcMWt10", value: "学习培训", isChecked: false, isDisabled: false,},
        {key: "pcMWt11", value: "参加会议", isChecked: false, isDisabled: false,},
        {key: "pcMWt12", value: "其他工作", isChecked: false, isDisabled: false,},
        {key: "pcMWt13", value: "休息未上班", isChecked: false, isDisabled: false,},
      ],
      personWorks: [],  // 工作日志选择项信息
      remark: this.dayLog.remarkManu, // 备注
    }
  },
  created() {
    this.queryLogDayDetail();
  },
  methods: {
    queryLogDayDetail() {
      checkService.mlogDetail(this.dayLog).then(dr => {
        if (dr.success) {
          this.personWorks = JSON.parse(dr.bean.personWorks);
          // 将0,1转成false,true
          this.personWorks.map(p => {
            Object.keys(p).forEach(k => {
              k.startsWith("pcMWt") && (p[k] = !!p[k]);
            });
          });
          console.log("personWorks", this.personWorks);
        } else {
          this.$u.toast(dr.msg);
        }
      });
    },
    // 确定
    handlerSure() {
      // 将false,true转成0,1
      let pw = this.$u.deepClone(this.personWorks);
      pw.map(p => {
        Object.keys(p).forEach(k => {
          k.startsWith("pcMWt") && (p[k] = p[k] ? 1 : 0);
        });
      });
      let updateDayLog = this.$u.deepClone(this.dayLog);
      updateDayLog.personWorks = JSON.stringify(pw);
      updateDayLog.remarkManu = this.remark;
      // 提交更新
      this.$u.loading("提交中...");
      checkService.mlogUpdate(updateDayLog).then(dr => {
        this.$u.hideLoading();
        if (dr.success) {
          this.$u.toast("提交成功");
          this.$emit("back", true);
        } else {
          this.$u.toast(dr.msg);
        }
      });
    },
    handlerBack() {
      this.$emit("back", false);
    },
  },
}
</script>
<style lang="scss" scoped>
@import "@/style/common/rightMenu.scss";
.part-item-info {
  text-align: center;
  .main-info {
    color: rgb(3, 3, 3);
    margin-bottom: 5px;
  }
}
</style>